﻿using RabbitMQ.Client;
using System.Text;

namespace TopicPublisher
{
    internal class Program
    {
        static void Main(string[] args)
        {
            var factory = new ConnectionFactory() { HostName = "localhost" };
            var connection = factory.CreateConnection();
            var channel = connection.CreateModel();
            channel.ExchangeDeclare(exchange: "topic_log", type: "topic");
            var routingKey = (args.Length > 0) ? args[0] : "anonymous.info";
            var message = (args.Length > 1) ? string.Join(" ", args.Skip(1).ToArray()) : "Hello World";
            var body = Encoding.UTF8.GetBytes(message);
            channel.BasicPublish(exchange: "topic_log", routingKey: routingKey, basicProperties: null, body: body);
            Console.WriteLine($" [x] Sent '{routingKey}':'{message}'");
            Console.ReadLine();
        }
    }
}